package com.team.sion.mapper;

import com.team.sion.pojo.Song;
import com.team.sion.pojo.SongList;
import com.team.sion.pojo.SongListExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface SongListMapper {
    long countByExample(SongListExample example);

    int deleteByExample(SongListExample example);

    @Delete({
            "delete from songlist",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
            "insert into songlist (id, title, ",
            "pic, style, introduction)",
            "values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, ",
            "#{pic,jdbcType=VARCHAR}, #{style,jdbcType=VARCHAR}, #{introduction,jdbcType=VARCHAR})"
    })
    int insert(SongList row);

    int insertSelective(SongList row);

    List<SongList> selectByExample(SongListExample example);

    @Select({
            "select * from songlist s join (select songList_id " +
                    " from ranklist group by songlist_id order by avg(score) desc)a on s.id = a.songList_id"
    })
    List<SongList> selectByScore();

    @Select({
            "select",
            "id, title, pic, style, introduction",
            "from songlist",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.team.sion.mapper.SongListMapper.BaseResultMap")
    SongList selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("row") SongList row, @Param("example") SongListExample example);

    int updateByExample(@Param("row") SongList row, @Param("example") SongListExample example);

    int updateByPrimaryKeySelective(SongList row);

    @Update({
            "update songlist",
            "set title = #{title,jdbcType=VARCHAR},",
            "pic = #{pic,jdbcType=VARCHAR},",
            "style = #{style,jdbcType=VARCHAR},",
            "introduction = #{introduction,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(SongList row);
    @ResultMap("com.team.sion.mapper.SongMapper.BaseResultMap")
    @Select("select * from song where id in (select song_id from songlist_song where songList_id = #{songListId})")
    List<Song> findById(Integer songListId);
}